package cn.gson.crm.controller.student;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.GraduateDao;
import cn.gson.crm.model.dao.StudentDao;
import cn.gson.crm.model.entity.Student;

/**
 * 让班级内的学生毕业
 */
@WebServlet("/student/makestudentgraduate")
public class MakeStudentGraduateServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private StudentDao studentDao = new StudentDao();
	private GraduateDao graduateDao=new GraduateDao();
	String password="111111";

	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		//System.out.println(id);
		// 使已入学成为已毕业
		boolean gradresult = studentDao.updetaStudentToGraduate(6, id);
		if (!gradresult) {
			errorForward("毕业失败", "student/assignstudent.jsp");
			return;
		}
		String gradPassword=addPass(password);
		Student student=studentDao.getOneStudentById(id);
		boolean insertGraduateResult=graduateDao.insertGraduate(student,gradPassword);
		if(!insertGraduateResult){
			errorForward("系统错误", "student/assignstudent.jsp");
			return;
		}
		redirect("student/main");
	}
}
